﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Configuration;

/// <summary>
/// Summary description for Userlogin
/// </summary>
namespace Bestlife.ERP.DataAccess
{
	public class Userlogin
	{
       
        public static string getuser(string uname,string pwd)
        {
            string usertype="No User Type";
            SqlDataReader rdR;
            try
            {
                String connStr = ConfigurationManager.ConnectionStrings["BestlifeDBConnectionString"].ConnectionString;
                Bestlife.ERP.DataAccess.Connection.connect(connStr);


                String Ssql = "SELECT [Use_Type] FROM [Tbl_Admin_User] where Use_Name='" + uname + "' and Pas_Word='" + pwd + "' ";
                //SqlDataReader ldr = Bestlife.ERP.DataAccess.clsCon.ReadTable(Ssql);


                rdR = Connection.ReadTable(Ssql);



                if (rdR.Read())
                {
                   usertype = rdR["Use_Type"].ToString();
                    
                }

              
                rdR.Close();
                Connection.con.Close();
            }

            catch(Exception)
            {

            }
            //string error = "";
            //return error;
            return usertype;   
    }

        public static Boolean upd_pw(string uname, string pw)
        {
            Boolean status = false;
            DateTime date = System.DateTime.Now;

            String connStr = ConfigurationManager.ConnectionStrings["BestlifeDBConnectionString"].ConnectionString;
            Bestlife.ERP.DataAccess.Connection.connect(connStr);//connection string pass to connection class

            string sql = "UPDATE [Tbl_Admin_User]  SET [Last_Modify] ='" + date + "',[Pas_Word] ='" + pw + "' WHERE [Use_Name]='" + uname + "'";
            Boolean edit = Bestlife.ERP.DataAccess.Connection.AddEditDel(sql);
            if (edit)
            {
                status = true;

                return status;
            }

            return status;
        }

        public static string getpw(string uname)
        {
            string usertype = "No User Type";
            SqlDataReader rdR;
            try
            {
                String connStr = ConfigurationManager.ConnectionStrings["BestlifeDBConnectionString"].ConnectionString;
                Bestlife.ERP.DataAccess.Connection.connect(connStr);


                String Ssql = "SELECT [Pas_Word] FROM [Tbl_Admin_User] where Use_Name='" + uname + "' ";
                //SqlDataReader ldr = Bestlife.ERP.DataAccess.clsCon.ReadTable(Ssql);


                rdR = Connection.ReadTable(Ssql);



                if (rdR.Read())
                {
                    usertype = rdR["Pas_Word"].ToString();

                }


                rdR.Close();
                Connection.con.Close();
            }

            catch (Exception)
            {

            }
            //string error = "";
            //return error;
            return usertype;
        }
       
    }

}